Nota : A maioria dos computadores atuais não tem mais portas seriais.
Esta tarefa foi transferida para as portas USB.
Module PortaSerial
Sub SendSerialData(ByVal data As String)
' Send strings to a serial port.
Using com1 As IO.Ports.SerialPort = My.Computer.Ports.OpenSerialPort("COM4")
If com1.IsOpen Then
com1.BaudRate = "9600"
com1.DataBits = 8
com1.Parity = 0
com1.StopBits = 1
com1.WriteLine(data)
Else
MsgBox("A porta está fechada.")
End If
com1.Close()
End Using
End Sub
Private Sub ReceiveSerialData()
' Receive strings from a serial port.
Dim returnStr As String = ""
Dim Incoming As String
Dim com1 As IO.Ports.SerialPort = Nothing
Try
com1 = My.Computer.Ports.OpenSerialPort("COM4")
com1.BaudRate = "9600"
com1.DataBits = 8
com1.Parity = 0
com1.StopBits = 1
com1.ReadTimeout = 1000 '1seg
Do
Incoming = com1.ReadLine()
If Incoming Is Nothing Then
Exit Do
Else
returnStr &= Incoming & vbCrLf
End If
Loop
Catch ex As TimeoutException
returnStr = "Erro: Time out na leitura da porta Serial."
Finally
If com1 IsNot Nothing Then com1.Close()
End Try
MsgBox(returnStr)
End Sub